import { request } from "@/plugins/request";

//获取公共文章列表
export const getArticles = params => {
    return request({
        method: 'GET',
        url: '/api/articles',
        params
    });
}

export const getFeed = params => {
    return request({
        method: 'GET',
        url: '/api/articles/feed',
        params
    });
}

//添加点赞
export const addFavorite = slug => {
    return request({
        method: 'POST',
        url: `/api/articles/${slug}/favorite`
    });
}

//取消点赞
export const deleteFavorite = slug => {
    return request({
        method: 'DELETE',
        url: `/api/articles/${slug}/favorite`
    });
}

//获取文章详情
export const getArticle = slug => {
    return request({
        method: 'GET',
        url: `/api/articles/${slug}`
    });
}

//获取文章评论
export const getComments = slug => {
    return request({
        method: 'GET',
        url: `/api/articles/${slug}/comments`
    });
}

//添加文章评论
export const addComments = (slug, data) => {
    return request({
        method: 'POST',
        url: `/api/articles/${slug}/comments`,
        data
    });
}


//关注
export const addFollow = username => {
    return request({
        method: 'POST',
        url: `/api/profiles/${username}/follow`,
    });
}

//取消关注
export const deleteFollow = username => {
    return request({
        method: 'DELETE',
        url: `/api/profiles/${username}/follow`,
    });
}

//添加文章
export const addArticles = data => {
    return request({
        method: 'POST',
        url: `/api/articles`,
        data
    });
}

//更新文章
export const updateArticles = (slug,data) => {
    return request({
        method: 'PUT',
        url: `/api/articles/${slug}`,
        data
    });
}

//删除
export const deleteArticles = slug => {
    return request({
        method: 'DELETE',
        url: `/api/articles/${slug}`
    });
}